<html>
	<head>
		<title>Benvenuto su Multihands</title>
        <link href="css/style.css" rel="stylesheet" type="text/css">
		<script type="text/javascript"> 
            function stopRKey(evt) { 
                var evt = (evt) ? evt : ((event) ? event : null); 
                var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); 
                if ((evt.keyCode == 13) && (node.type=="text"))  {return false;} 
            } 
            document.onkeypress = stopRKey; 

            function check (){
            	var x=document.getElementById("doc");
            	if (x.value.length == 0){
            		alert('Devi inserire un nome, oppure clicca su un documento gia creato');
            	}
            	else if (x.value.length > 245){
            		alert("Il nome non puo' essere piu' lungo di 245 caratteri");
            	}
            	else {
            		if (x.value.search(/[\/\,\*\._\\\|\[\]{}\s+\@\#\$\^\&\'\"\(\)\:]/) != -1 ){
            			alert('Carattere vietato!');
            			x.value = "";
            		}
                    else if (x.value.search(/null/i) != -1 ){
                        alert("Il nome del documento non puo' essere uguale a null");
                        x.value = "";
                    }
            		else {
                        setTimeout(function (){
                            var doc = document.getElementById("goEditor")
                            doc.value = x.value
                            doc.submit();
                            x.disabled = true;
                            document.getElementById("invio").disabled = true;
                        },0)
            		}
            	}
            }
            function keyPress(e){
            	if (!e) e = window.event; // needed for cross browser compatibility 
 				if (e.keyCode == 13) {
 					check();
 				}
			}
		</script>
	</head>
	<body>
        <div class="wrapper">
            <div class="page">
                <div class="main-container col1-layout">
                    <div class="header-container"> </div>
                    <div class="main">
                        <div class="col-main">
                            <div class ='std'>
                                {{#each documents}}
                                    <p>
                                        <a href="/editor.html?titolo={{this}}">
                                            {{this}}
                                        </a>
                                    </p>
                                {{/each}}
                                <form id="goEditor" method='get' action='/editor.html' onsubmit="keyPress()">
                                    Nome documento <input id="doc" type="text" name="titolo" onkeypress="keyPress()"/>
                                    <input type="button" id='invio' value="Submit" onclick="check()" />
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="footer-container">
                    <div class="footer">
                        <address>Copyright 2013 Pad company.</address>
                    </div>
                </div>
            </div>     
        </div>
	</body>
</html>	